package view;

import controllers.RegisterInterfaceControllers;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @author zjw
 * @date 2020/1/5 21:26
 */
public class RegisterInterface {
    private Stage primaryStage;
    private GridPane grid = new GridPane();
    private Label userNameLabel = new Label("昵称:");
    private Label passwordLabel = new Label("密码:");
    private Label passwordAgainLabel = new Label("密码确认:");
    private TextField userNameTextField;
    private PasswordField passwordField;
    private PasswordField passwordAgainField;
    private Button registerButton;
    private Button returnButton;

    public RegisterInterface(Stage primaryStage) {
        this.primaryStage = primaryStage;
        grid = new GridPane();
        userNameTextField = new TextField();
        passwordField = new PasswordField();
        passwordAgainField = new PasswordField();

        RegisterInterfaceControllers registerInterfaceController = new RegisterInterfaceControllers(primaryStage, userNameTextField, passwordField, passwordAgainField);
        registerButton = registerInterfaceController.getRegisterButton();
        returnButton = registerInterfaceController.getReturnButton();

    }

    public void start() throws Exception {
        initInterface();

        Scene scene = new Scene(grid,430,330);
        scene.getStylesheets().add(RegisterInterface.class.getResource("css/RegisterCss.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setTitle("Register Interface");
        primaryStage.show();
    }

    private void initInterface() {
        HBox buttonHorizontalBox = new HBox(2);
        buttonHorizontalBox.setAlignment(Pos.BOTTOM_RIGHT);

        buttonHorizontalBox.setSpacing(30);
        buttonHorizontalBox.getChildren().addAll(registerButton, returnButton);

        grid.setAlignment(Pos.CENTER);
        grid.setHgap(20);
        grid.setVgap(20);
        grid.setPadding(new Insets(25,25,25,25));
        grid.add(userNameLabel,0,0);
        grid.add(userNameTextField,1,0);
        grid.add(passwordLabel,0,1);
        grid.add(passwordField,1,1);
        grid.add(passwordAgainLabel,0,2);
        grid.add(passwordAgainField,1,2);
        grid.add(buttonHorizontalBox,1,3);
    }
}
